/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import entidade.Cliente;
import java.util.List;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author lsalves
 */
@Stateful
public class ClienteBean implements ClienteBeanRemote {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @PersistenceContext
    private EntityManager em;
    
    @Override
    public Object getCliente(String cliNome){        
      Query query = em.createQuery("select c from Cliente c where c.nome= "+cliNome);      
      List <ClienteBean> cliente = query.getResultList();      
      return cliente.get(0);
    }
    
    
    @Override
    public List <Object> getClientes() {
      Query query = em.createQuery("select c from Cliente c");      
      List <Object> cliente = query.getResultList();      
      return cliente;
    }
    
     @Override
    public void createCliente(Object cliente) {
        em.persist((Cliente)cliente);
    }

    @Override
    public void removeCliente(Object cliente) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
    @Override
    public void updateCliente(Object cliente) {
        em.merge((Cliente)cliente);
    }

    
}
